<?php include_once 'include.php';
check_login();//判断是否登录
?>
<!DOCTYPE html>
<html>
<head>
    <?php include_once 'common_js_css.php'?>
    <link rel="stylesheet" type="text/css" href="css/aduser.css">
    <script src="js/adapter.js"></script>
</head>
<body>
<!-- 右边 B -->
<div class="cont" style="height: 730px">
    <h1 style="text-align: center;">管理员个人信息</h1>
    <form id="form1" style="margin-left: 380px;margin-top: 40px">
        <table id="cont" width="331" height="300" align="center" cellspacing="0">
            <tr>
                <td height="30" align="center" valign="middle">账号</td>
                <td height="30" align="left" valign="middle"><b><?php echo $_SESSION['name']; ?></b>
            </tr>
            <tr>
                <td height="30" align="center" valign="middle">角色</td>
                <td height="30" align="left" valign="middle">
                    <b><?php if ($_SESSION['identity']==1)echo '管理员';else{echo '普通用户';} ?></b></td>
            </tr>
            <tr>
                <td height="30" colspan="2" align="center" valign="middle">修改密码</td>
            </tr>
            <tr>
                <td height="30" align="center" valign="middle">原密码：</td>
                <td height="30" align="left" valign="middle"><label for="adpwd"></label>
                    <input name="adpwd2" type="password" id="adpwd" size="20" maxlength="20" class="txt"></td>
            </tr>
            <tr>
                <td height="30" align="center" valign="middle">新密码</td>
                <td height="30" align="left" valign="middle"><label for="adnewpwd"></label>
                    <input name="adnewpwd" type="password" id="adnewpwd" size="20" maxlength="20" class="txt"></td>
            </tr>
            <tr>
                <td height="30" align="center" valign="middle">确认密码：</td>
                <td height="30" align="left" valign="middle"><label for="renewpwd"></label>
                    <input name="renewpwd" type="password" id="renewpwd" size="20" maxlength="20" class="txt"></td>
            </tr>
            <tr>
                <td height="30" align="center" valign="middle"><input type="button" name="ad1" id="ad1" value="确定" onclick="update_pwd(2)"></td>
                <td height="30" align="left" valign="middle"><input type="reset" name="ad2" id="ad2" value="重置" onclick="$('#form1').reset()"></td>
            </tr>
        </table>
    </form>
</div>
<!-- 右边 E -->
<script>
    //修改密码
    function update_pwd() {
        var oldpwd = $("#adpwd").val(),
            newpwd = $("#adnewpwd").val(),
            renewpwd = $("#renewpwd").val();
        if (oldpwd==""||oldpwd==null){
            $("#adpwd").after("<span id='adpwds' style='color: red'>原密码不能为空</span>");
        }if (newpwd==""||newpwd==null){
            $("#adnewpwd").after("<span id='adnewpwds' style='color: red'>新密码不能为空</span>");
        }if (renewpwd==""||renewpwd==null){
            $("#renewpwd").after("<span id='renewpwds' style='color: red'>确认密码不能为空</span>");
        }else if (renewpwd!=newpwd){
            $("#renewpwd").after("<span id='renewpwds' style='color: red'>两次密码不一致</span>");
        }else{
            post_data={
                oldpwd:oldpwd,
                newpwd:newpwd
            };
            $.post('doAction.php?act=edit_pwd',post_data,function (data) {
                console.log(data);
                if (data==200){
                    alert('修改密码成功，请重新登录');
                    window.location = 'adlogin.php';
                }else {
                    alert(data);
                }
            })
        }
    }
</script>
</body>
</html>